package one.three.thirtyFour;

import java.util.Iterator;

public class MyArray implements Iterable<Integer> {

	private int[] a;

	@Override
	public Iterator<Integer> iterator() {

		return new MyIte();
	}

	private class MyIte implements Iterator<Integer> {
		int n = 0;

		public MyIte() {
			System.out.println("I");
		}

		@Override
		public boolean hasNext() {

			return n < a.length;
		}

		@Override
		public Integer next() {
			int r = a[n];
			n++;
			return r;
		}

	}

	public static void main(String[] args) {
		MyArray a = new MyArray();
		a.a = new int[3];
		for (int i = 0; i < 3; i++) {
			a.a[i] = i * i;
		}

		for (Integer i : a) {
			System.out.println(i);
		}

		for (Integer i : a) {
			System.out.println(i);
		}

	}

}
